package hy.mvpdemo.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import hy.mvpdemo.R;
import hy.mvpdemo.model.bean.NewsBean;
import hy.mvpdemo.model.util.ApiService;

/**
 * Created by hy on 2016/10/23.
 */

public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.MyViewHolder> {


    private List<NewsBean.TngouBean> mDatas;
    private Context mContext;
    private LayoutInflater inflater;


    public NewsAdapter(Context context, List<NewsBean.TngouBean> newsdata) {
        this.mContext = context;
        this.mDatas = newsdata;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getItemCount() {

        return mDatas.size();
    }

    //填充onCreateViewHolder方法返回的holder中的控件
    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.tvarttitle.setText(mDatas.get(position).getTitle());
        holder.tvarticetype.setText("社会热点");
        Glide.with(holder.tvarticetype.getContext())
                .load(ApiService.PICTURE_ROOT_LOADURL+mDatas.get(position).getImg())
                .into(holder.svartlogo);


    }

    //重写onCreateViewHolder方法，返回一个自定义的ViewHolder
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = inflater.inflate(R.layout.news_item_plus, parent, false);


        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        private ImageView svusericon;
        private TextView tvarticename;
        private TextView tvarticeputtime;
        private TextView tvarttitle;
        private TextView tvarticetype;
        private LinearLayout llrootline;
        private ImageView svartlogo;
        private RelativeLayout rlroot;

        public MyViewHolder(View view) {
            super(view);
            this.rlroot = (RelativeLayout) view.findViewById(R.id.rl_root);
            this.svartlogo = (ImageView) view.findViewById(R.id.sv_art_logo);
            this.llrootline = (LinearLayout) view.findViewById(R.id.ll_root_line);
            this.tvarticetype = (TextView) view.findViewById(R.id.tv_artice_type);
            this.tvarttitle = (TextView) view.findViewById(R.id.tv_art_title);
            this.tvarticeputtime = (TextView) view.findViewById(R.id.tv_artice_puttime);
            this.tvarticename = (TextView) view.findViewById(R.id.tv_artice_name);
            this.svusericon = (ImageView) view.findViewById(R.id.sv_usericon);

        }

    }


}
